package com.yykj.pharmacist.server.service.impl;

import com.yykj.common.enums.ResultEnums;
import com.yykj.common.exception.NormalException;
import com.yykj.common.vo.ResultVO;
import com.yykj.pharmacist.server.model.entity.PharmacistCheckLog;
import com.yykj.pharmacist.server.model.repository.PharmacistCheckLogRepository;
import com.yykj.pharmacist.server.service.PharmacistService;
import com.yykj.prescription.client.dto.PrescriptionCheckDTO;
import com.yykj.prescription.client.feign.PrescriptionFeignClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PharmacistServiceImpl implements PharmacistService {

    @Override
    public void checkPrescription(PrescriptionCheckDTO checkDTO) {
        ResultVO resultVO = prescriptionFeignClient.checkPrescription(checkDTO);
        if(resultVO.getCode() == 0){
            PharmacistCheckLog log  = new PharmacistCheckLog();
            BeanUtils.copyProperties(checkDTO,log);
            pharmacistCheckLogRepository.save(log);
        }else{
            throw new NormalException(ResultEnums.NOT_EXIST,resultVO.getMsg());
        }

    }
    private PharmacistCheckLogRepository pharmacistCheckLogRepository;

    private PrescriptionFeignClient prescriptionFeignClient;

    @Autowired
    public void setPharmacistCheckLogRepository(PharmacistCheckLogRepository pharmacistCheckLogRepository) {
        this.pharmacistCheckLogRepository = pharmacistCheckLogRepository;
    }

    @Autowired
    public void setPrescriptionFeignClient(PrescriptionFeignClient prescriptionFeignClient) {
        this.prescriptionFeignClient = prescriptionFeignClient;
    }
}
